<?php
namespace Home\Controller;
use Think\Controller;
class ClubController extends Controller {
        public function clublist(){ //俱乐部列表-赵明月

        $admin = M('clubadmin');
        $c_tel=$_SESSION['c_tel'];
        $admins=$admin->where("c_tel='$c_tel'")->find();
        $this->admin=$admins;
       $clubname=$admin->clubname;
       $clubs = M('club');
       $res = $clubs->where("club_name='$clubname'")->select();
       $c=$res['0']['cid'];
      $this->qrcodeList=$res;
        $teachers = M('teacher');
        $res1 = $teachers->where("cid='$c'")->select();
        //var_dump($res1);
        $this->list1=$res1;
      $this->display();

    }
  

    function editclub($cid){//修改俱乐部-赵明月

         $admin = M('clubadmin');
        $c_tel=$_SESSION['c_tel'];
        $admins=$admin->where("c_tel='$c_tel'")->find();
        $this->admin=$admins;

        $clubs = M('club');
        $cid = $_GET['cid'];
        $res = $clubs->where("cid=$cid")->find($data);
        //dump($res);
        $this->list=$res;
        $this->display();
    }
    function doUpdate($cid){//修改俱乐部-赵明月

        $admin = M('clubadmin');
        $c_tel = $_SESSION['c_tel'];
        $admins=$admin->where("c_tel='$c_tel'")->find();
        $this->admin=$admins;
        $clubname=$admin->clubname;
        $clubs = M('club');
        $res = $clubs->where("club_name='$clubname'")->select();

        if($_FILES['club_pic']['error'] == 0){
            $logoinfo = $this->MyUpload();
            $pname = $logoinfo['file']['savename'];
        } else {
            $pname = "default.jpg";
        }
       
        $data['club_name']=I('post.club_name');
        $data['club_intro']=I('post.club_intro');
        $data['club_tele']=I('post.club_tele');
        $data['club_address']=I('post.club_address');
        $data['club_time']=I('post.club_time');
        $data['club_pic'] = $pname;
        $datas['clubname']=I('post.club_name');

        $res1=$clubs->where("cid='$cid'")->save($data);
        $res2=$admin->where("c_tel='$c_tel'")->save($datas);
        if (false!==$res1&&false!==$res2){
            $this->success('信息修改成功',U('clublist'));
        } else{
            $this->error('信息修改失败');
        }

   
}
   
 
     public function MyUpload(){//上传图片-赵明月
                //上传头像
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize  = 3145728 ;// 设置附件上传大小
        //$upload->allowExts  = array('mp4','jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->exts  = array('jpg', 'gif', 'png', 'jpeg');
        $upload->rootPath  =  './';
        $upload->savePath =  'Public/upload/clubpic/';// 设置附件上传目录

        $upload->autoSub = false;
        $upload->saveName = date("YmdHis").rand(100,999);//定义名字
        // 上传单个文件 
        $info = $upload->upload();                    
            if(!$info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }else{// 上传成功 获取上传文件信息
                return $info;
            }
    } 

 public function delclub($cid){//删除俱乐部-赵明月
   
       $clubsModel=M('club');
        $res=$clubsModel->where("cid=$cid")->find();
        $photoPath = realpath("./Public/upload/clubpic/".$res['club_pic']);
        unlink($photoPath);
        //$res=$usersmodel->where("id=$id")->delete();
        if ($clubsModel->delete($cid)) {
            $this->success('删除成功！');
        } else {
            $this->error('删除失败');
        }
    }

 
 public function detail($cid){//俱乐部详情-赵明月
    $admin = M('clubadmin');
        $c_tel = $_SESSION['c_tel'];
        $admins=$admin->where("c_tel='$c_tel'")->find();
        $this->admin=$admins;
        $clubname=$admin->clubname;

       $clubs=M('club');//实例化一个model对象
        $res=$clubs->where("cid = $cid")->select();//asc升序 desc降序
        //$this->detail=$res;
        $c=$res['0']['cid'];
        $this->detail=$res;
        $teachers = M('teacher');
        $res1 = $teachers->where("cid='$c'")->select();
        //var_dump($res1);
        $this->list1=$res1;
        $this->display();

 }

 

 
 
}